import Vue from "vue"
import VueRouter from "vue-router"
import login from "./components/login.vue"
import register from "./components/register.vue"
import index from "./components/index.vue"
import notFound from "./components/404.vue"
import shopCart from "./components/shopCart.vue"
import confirmOrderInfo from "./components/confirmOrderInfo.vue"
import payResult from "./components/payResult.vue"
import admin from "./components/admin.vue"
Vue.use(VueRouter)
const router = new VueRouter({
    routes:[
        {path:"/",component:index,meta:{
            title:"首页"
        }},
        {path:"/login",component:login,meta:{
            title:"登陆页面"
        }},
        {path:"/register",component:register,meta:{
            title:"注册页面"
        }},
        {path:"/shopcart",component:shopCart,meta:{
            title:"查看购物车"
        }}, 
        {path:"/confirmorderinfo",component:confirmOrderInfo,meta:{
            title:"确认订单信息"
        }},
        {path:"/payresult/:payResult/:orderId",component:payResult,meta:{
            title:"支付情况"
        }},
        {path:'/admin',component:admin,meta:{
            title:"后台管理"
        }},                        
        {path:"*",component:notFound}
        
    ]
})
router.beforeEach((to, from, next) => {
    if (to.meta.title) {
        document.title=to.meta.title;
    }    
    if(to.path=='/admin'){
        if(!to.query.id){
            next('/');  
        }
    }
    next();          
})
export default router;